package com.special.threademo.Controller;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.special.threademo.common.qrcode.QRcodeUtil;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LiuYC
 * @version 1.0.0
 * @create 2020-12-29 0:13
 */
public class QRcodeTest {
    public static void main(String[] args) {
        try {
            //二维码访问的网址地址1：www.baidu.com或者http://baidu.com
            String content = "http://baidu.com";
            //二维码图片保存的路径
            String path ="C://Users/liudaka/Desktop";
            MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
            Map hints = new HashMap();
            hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
            BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 100, 100,hints);
            File file1 = new File(path,"百度首页.jpg");
            QRcodeUtil.writeToFile(bitMatrix, "jpg", file1);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
